package zzzhc.image.recognize.filter;

import zzzhc.image.recognize.Filter;
import zzzhc.image.recognize.RecognizeContext;

public class GrayLevelFilter implements Filter {

	private static final long serialVersionUID = -4314922963874952684L;

	private int grayMinLevel = 0;

	private int grayMaxLevel = 150;

	public void doFilter(RecognizeContext context) {
		int h = context.getHeight();
		int w = context.getWidth();
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				int p = context.getValue(x, y);
				if (p >= grayMinLevel && p <= grayMaxLevel) {
					p = 1;
				} else {
					p = 0;
				}
				context.setValue(x, y, p);
			}
		}
		context.setBinary(true);
	}

	public int getGrayMinLevel() {
		return grayMinLevel;
	}

	public void setGrayMinLevel(int grayLevel) {
		this.grayMinLevel = grayLevel;
	}

	public int getGrayMaxLevel() {
		return grayMaxLevel;
	}

	public void setGrayMaxLevel(int grayMaxLevel) {
		this.grayMaxLevel = grayMaxLevel;
	}

}
